//
//  NewestTableViewCell.m
//  SoundPill
//
//  Created by 宋旭东 on 15/11/30.
//  Copyright © 2015年 宋旭东. All rights reserved.
//

#import "NewestTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#import "AFNetworking.h"
#import "AppDelegate.h"
#import "JCAlertView.h"
#define kleftGap  5
#define kupGap   8
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kImageViewWidth [UIScreen mainScreen].bounds.size.width*0.07
#define kImageViewHeight 157
#define kLabelWidth [UIScreen mainScreen].bounds.size.width*0.18
#define kLabelHeight 20

@interface NewestTableViewCell ()
{
    
}
@property (strong, nonatomic) UIImageView *avatarView;
@property (strong, nonatomic) UIImageView *sexView;
@property (strong, nonatomic) UIImageView *workCoverView;
@property (strong, nonatomic) UIImageView *workPointIcon;
@property (strong, nonatomic) UIImageView *workSecondIcon;
@property (strong, nonatomic) UIImageView *playCountIcon;
@property (strong, nonatomic) UIImageView *loveCountIcon;
@property (strong, nonatomic) UIImageView *cashCountIcon;

@property (strong, nonatomic) UILabel *userNameLabel;
@property (strong, nonatomic) UILabel *workPointLabel;
@property (strong, nonatomic) UILabel *workSecondLabel;
@property (strong, nonatomic) UILabel *workNameLabel;
@property (strong, nonatomic) UILabel *playCountLabel;
@property (strong, nonatomic) UILabel *loveCountLabel;
@property (strong, nonatomic) UILabel *cashCountLabel;
@property (strong, nonatomic) UILabel *textMarkLabel;
@property (strong, nonatomic) UILabel *imageMarkLabel;

@property (strong, nonatomic) UIView *coverBackgroundView;
@property (strong, nonatomic) UIButton *userInfoButton;
@property (strong, nonatomic) UIButton *attentionButton;
@end

@implementation NewestTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
        //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.backgroundColor=[UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}
- (void)initSubViews
{
    self.avatarView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_avatarView];
    
    self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_userNameLabel];
    
    self.sexView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_sexView];
    
    self.attentionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_attentionButton];
    
    self.workCoverView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_workCoverView];
    
    _coverBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    [self addSubview:_coverBackgroundView];
    
    self.workPointLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_workPointLabel];
    [_workPointLabel setTextColor:[UIColor whiteColor]];
    [_workPointLabel setFont:[UIFont systemFontOfSize:45.0f]];
    
    self.workSecondLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_workSecondLabel];
    [_workSecondLabel setTextColor:[UIColor whiteColor]];
    [_workSecondLabel setFont:[UIFont systemFontOfSize:45.0f]];
    
    self.workPointIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_workPointIcon];

    self.workSecondIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_workSecondIcon];
    
    self.workNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_workNameLabel];
    _workNameLabel.font = [UIFont systemFontOfSize:17.0f];
    _workNameLabel.textColor = [UIColor whiteColor];
    
    self.playCountIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_playCountIcon];
    
    self.playCountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_playCountLabel];
    
    self.loveCountIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_loveCountIcon];
    
    self.loveCountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_loveCountLabel];
    
    self.cashCountIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_cashCountIcon];
    self.cashCountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_cashCountLabel];
    
    self.userInfoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_userInfoButton];
    
    self.textMark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play_blackMark"]];
    _textMark.frame = CGRectZero;
    [self addSubview:_textMark];
    
    self.imageMark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play_blueMark"]];
    _imageMark.frame = CGRectZero;
    [self addSubview:_imageMark];
    
    self.textMarkLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _textMarkLabel.text = @"字幕";
    _textMarkLabel.textColor = [UIColor whiteColor];
    _textMarkLabel.textAlignment = NSTextAlignmentRight;
    _textMarkLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_textMarkLabel];
    
    self.imageMarkLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _imageMarkLabel.text = @"插图";
    _imageMarkLabel.textColor = [UIColor whiteColor];
    _imageMarkLabel.textAlignment = NSTextAlignmentRight;
    _imageMarkLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_imageMarkLabel];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    //用户头像
    _avatarView.frame = CGRectMake(kleftGap * 3, kleftGap * 3, 25, 25);
    if (![[self.model.user valueForKey:@"avatar"] isEqual:[NSNull null]]) {
        [_avatarView setImageWithURL:[NSURL URLWithString:[self.model.user valueForKey:@"avatar"]] placeholderImage:[UIImage imageNamed:@"default_head.png"]];
    } else {
        _avatarView.image = [UIImage imageNamed:@"default_head.png"];
    }
    //用户名
    _userNameLabel.textColor = [UIColor blackColor];
    if ([UIScreen mainScreen].bounds.size.width == 320) {
        _userNameLabel.frame = CGRectMake(_avatarView.right + 10, _avatarView.top, self.contentView.width*0.4, _avatarView.frame.size.height);
        _userNameLabel.font = [UIFont boldSystemFontOfSize:12];
    } else if ([UIScreen mainScreen].bounds.size.height == 667) {
        _userNameLabel.frame = CGRectMake(_avatarView.right + 10, _avatarView.top, self.contentView.width*0.4, _avatarView.frame.size.height);
        _userNameLabel.font = [UIFont boldSystemFontOfSize:14];
    } else if ([UIScreen mainScreen].bounds.size.height == 736) {
        _userNameLabel.frame = CGRectMake(_avatarView.right + 10, _avatarView.top, self.contentView.width*0.4, _avatarView.frame.size.height);
        _userNameLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    if (![[self.model.user valueForKey:@"username"] isEqual:[NSNull null]]) {
        _userNameLabel.text = [NSString stringWithFormat:@"%@",[self.model.user valueForKey:@"username"]];
    }
    //用户性别
    CGSize w = [self boundingRectWithSize:_userNameLabel.frame.size text:_userNameLabel.text font:_userNameLabel.font];
    if ([_model.user valueForKey:@"sex"] != nil) {
        _sexView.frame = CGRectMake(_userNameLabel.frame.origin.x + w.width + 5, _avatarView.top, w.height-2, w.height-2);
        _sexView.center = CGPointMake(_userNameLabel.frame.origin.x + w.width + 12, _userNameLabel.frame.origin.y + _userNameLabel.frame.size.height/2);
        if ([[_model.user valueForKey:@"sex"] intValue] == 0) {
            _sexView.image = [UIImage imageNamed:@"aliens_btn"];
        } else if ([[_model.user valueForKey:@"sex"] intValue] == 1) {
            _sexView.image = [UIImage imageNamed:@"man_btn"];
        } else {
            _sexView.image = [UIImage imageNamed:@"girl_btn"];
        }
    }
    //用户关系按钮
    
    _attentionButton.frame = CGRectMake(self.frame.size.width - 15 - _avatarView.frame.size.width * 2.7, _avatarView.top - 2.5, _avatarView.frame.size.width * 2.7, _avatarView.frame.size.height + 5);
    _attentionButton.center = CGPointMake(self.frame.size.width - 15 - _attentionButton.frame.size.width / 2, _avatarView.center.y);
    _attentionButton.hidden = NO;
//    _attentionButton.backgroundColor = [UIColor redColor];
    NSNumber *attentionNum = [_model.user valueForKey:@"follow"];
    if ([attentionNum intValue] == 0) {
//        NSLog(@"%@,%@",[_model.user valueForKey:@"username"], [_model.user valueForKey:@"follow"]);
//        [_attentionButton setTitle:@" " forState:UIControlStateNormal];
        [_attentionButton setImage:[UIImage imageNamed:@"NewstAten"] forState:UIControlStateNormal];
        [_attentionButton setTitle:nil forState: UIControlStateNormal];
        _attentionButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_attentionButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    } else if([attentionNum intValue] > 0)  {
//         NSLog(@"1111%@,%@",[_model.user valueForKey:@"username"], [_model.user valueForKey:@"follow"]);
        [_attentionButton setImage:nil forState:UIControlStateNormal];
        [_attentionButton setTitle:@"已关注" forState: UIControlStateNormal];
        _attentionButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_attentionButton setTitleColor:[UIColor colorWithRed:0.600f green:0.600f blue:0.600f alpha:1.00f] forState:UIControlStateNormal];
        _attentionButton.layer.borderColor = [[UIColor clearColor] CGColor];
        _attentionButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -25);
    } else if ([attentionNum intValue] == -1) {
        _attentionButton.hidden = YES;
    }
    [_attentionButton addTarget:self action:@selector(changeAttention:) forControlEvents:UIControlEventTouchUpInside];
    
    //封面
    if ([UIScreen mainScreen].bounds.size.height == 667) {
        //6
        _workCoverView.frame = CGRectMake(kleftGap * 3, _avatarView.bottom + 10, kDeviceWidth - kleftGap * 6, 187);
    } else if ([UIScreen mainScreen].bounds.size.height == 736) {
        _workCoverView.frame = CGRectMake(kleftGap * 3, _avatarView.bottom + 10, kDeviceWidth - kleftGap * 6, 220);
    } else {
        _workCoverView.frame = CGRectMake(kleftGap * 3, _avatarView.bottom + 10, kDeviceWidth - kleftGap * 6, 145);
    }
    [_workCoverView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    _workCoverView.contentMode =  UIViewContentModeScaleAspectFill;
    _workCoverView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _workCoverView.clipsToBounds  = YES;
    if (![self.model.cover isEqual:[NSNull null]]) {
//        __weak NewestTableViewCell *cell = self;
        [_workCoverView setImageWithURL:[NSURL URLWithString:_model.cover] placeholderImage:[UIImage imageNamed:@"plazz_placeholderImage"]options:SDWebImageRetryFailed progress:^(NSUInteger receivedSize, long long expectedSize) {
//            cell.imageProgress.hidden = NO;
//            cell.imageProgress.progress = receivedSize / (float)expectedSize;
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                cell.imageProgress.hidden = YES;
//            });
        }];
    }
    
    _coverBackgroundView.frame = CGRectMake(_workCoverView.frame.origin.x, _workCoverView.frame.origin.y, _workCoverView.frame.size.width, _workCoverView.frame.size.height);
    _coverBackgroundView.backgroundColor = [UIColor blackColor];
    _coverBackgroundView.alpha = 0.33;
    
    //时长
    if ([UIScreen mainScreen].bounds.size.width == 320) {
        _workPointLabel.frame = CGRectMake(self.frame.size.width * 0.55 - 30, _workCoverView.frame.origin.y + 25 ,28+30 , 38);
    } else if ([UIScreen mainScreen].bounds.size.height == 667) {
        _workPointLabel.frame = CGRectMake(self.frame.size.width * 0.55 - 5, _workCoverView.frame.origin.y + 25 ,28+30 , 38);
    } else if ([UIScreen mainScreen].bounds.size.height == 736) {
        _workPointLabel.frame = CGRectMake(self.frame.size.width * 0.55 + 10, _workCoverView.frame.origin.y + 25 ,28+30 , 38);
    }
    _workPointLabel.textAlignment = NSTextAlignmentRight;
    if (![self.model.duration isEqual:[NSNull null]]) {
        int point =  _model.duration.floatValue / 60;
        _workPointLabel.text = [NSString stringWithFormat:@"%2d", point];
    }
    _workPointIcon.frame = CGRectMake(_workPointLabel.frame.origin.x + _workPointLabel.frame.size.width, _workPointLabel.frame.origin.y - 2, 12, 12);
    [_workPointIcon setImage:[UIImage imageNamed:@"minute"]];

    _workSecondLabel.frame = CGRectMake(_workPointIcon.frame.origin.x + _workPointIcon.frame.size.width + 3,_workPointIcon.frame.origin.y, 56, 38);
    _workSecondLabel.textAlignment = NSTextAlignmentCenter;
    if (![self.model.duration isEqual:[NSNull null]]) {
        //文字
        NSString *recommendString = [NSString stringWithFormat:@"%@",self.model.duration];
        int second = (int)recommendString.floatValue % 60;
        if (second < 10) {
            _workSecondLabel.text = [NSString stringWithFormat:@"0%d", second];
        }else{
            _workSecondLabel.text = [NSString stringWithFormat:@"%d", second];
        }
    }
    // "
    _workSecondIcon.frame = CGRectMake(_workSecondLabel.frame.origin.x + _workSecondLabel.frame.size.width, _workPointIcon.frame.origin.y, 12, 12);
    [_workSecondIcon setImage:[UIImage imageNamed:@"second"]];
    
    //标题
    _workNameLabel.frame = CGRectMake(50,  _workPointLabel.frame.origin.y + _workPointLabel.frame.size.height + 10, self.contentView.frame.size.width - 100, 44);
    [_workNameLabel setFont:[UIFont systemFontOfSize: 18.0f]];
    _workNameLabel.numberOfLines = 0;
    _workNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _workNameLabel.textAlignment = NSTextAlignmentRight;
    //_titleLabel.backgroundColor = [UIColor cyanColor];
    if (![self.model.title isEqual:[NSNull null]]) {
        NSString *recommendString = [NSString stringWithFormat:@"%@\n",self.model.title];
        _workNameLabel.text = recommendString;
    }
    
    // 播放图片
    _playCountIcon.frame = CGRectMake(_workCoverView.left - 6, _workCoverView.bottom + 5, 22, 22);
    _playCountIcon.image = [UIImage imageNamed:@"playicon"];
    //播放次数
    _playCountLabel.textAlignment = NSTextAlignmentLeft;
    _playCountLabel.font = [UIFont systemFontOfSize:13.0f];
    _playCountLabel.textColor = [UIColor blackColor];
    if (![self.model.play_count isEqual:[NSNull null]]) {
        _playCountLabel.text = [NSString stringWithFormat:@"%@",self.model.play_count];
        CGSize playSize = [self boundingRectWithSize:CGSizeMake(30, 20) text:_playCountLabel.text font:_playCountLabel.font];
        _playCountLabel.frame = CGRectMake(_playCountIcon.right, _playCountIcon.top, playSize.width, 22);
    }
    // 点赞图片
    _loveCountIcon.frame = CGRectMake(_playCountLabel.right + 5, _playCountIcon.top, 22, 22);
    _loveCountIcon.image = [UIImage imageNamed:@"loveicon"];
    
    // 点赞次数
    _loveCountLabel.font = [UIFont systemFontOfSize:13.0f];
    _loveCountLabel.textColor = [UIColor blackColor];
    _loveCountLabel.textAlignment = NSTextAlignmentLeft;
    if (![self.model.love_count isEqual:[NSNull null]]) {
        _loveCountLabel.text = [NSString stringWithFormat:@"%@",self.self.model.love_count];
        CGSize loveSize = [self boundingRectWithSize:CGSizeMake(30, 20) text:_loveCountLabel.text font:_loveCountLabel.font];
        _loveCountLabel.frame = CGRectMake(_loveCountIcon.right, _loveCountIcon.top, loveSize.width, 22);
    }
    if (_model.price.floatValue != 0.0f) {
        _cashCountIcon.hidden = NO;
        _cashCountLabel.hidden = NO;
        _cashCountIcon.frame = CGRectMake(_loveCountLabel.right + 5, _playCountIcon.top, 22, 22);
        _cashCountIcon.image = [UIImage imageNamed:@"cashIcon@3x"];
        _cashCountLabel.frame = CGRectMake(_cashCountIcon.right, _cashCountIcon.top, 50, 22);
        _cashCountLabel.textAlignment = NSTextAlignmentLeft;
        _cashCountLabel.textColor = [UIColor blackColor];
        _cashCountLabel.font = [UIFont systemFontOfSize:13.0f];
        _cashCountLabel.text = _model.price;//[NSString stringWithFormat:@"%.2f",_model.price.floatValue];
    } else {
        _cashCountIcon.hidden = YES;
        _cashCountLabel.hidden = YES;
    }
    
    
    self.tagView.frame = CGRectMake( 1, _loveCountLabel.top - 2, [UIScreen mainScreen].bounds.size.width, 20);
    
    _userInfoButton.frame = CGRectMake(_avatarView.left, _avatarView.top, _avatarView.frame.size.width + _userNameLabel.frame.size.width, _avatarView.frame.size.height);
    [_userInfoButton addTarget:self action:@selector(touchUser:) forControlEvents:UIControlEventTouchUpInside];
    
    if (_model.blue.boolValue == YES) {
        _imageMark.frame = CGRectMake(_workSecondIcon.right - 45, _workCoverView.bottom - 30, 15, 15);
        _imageMarkLabel.frame = CGRectMake(_imageMark.right, _imageMark.top, 30, 20);
        _imageMarkLabel.center = CGPointMake(_imageMark.center.x + 20, _imageMark.center.y);
        _imageMarkLabel.hidden = NO;
        _imageMark.hidden = NO;
        [self addAnimation:_imageMark repeate:MAXFLOAT];
    } else {
        _imageMark.hidden = YES;
        _imageMarkLabel.hidden = YES;
        [_imageMark.layer removeAllAnimations];
    }
    
    if (_model.black.boolValue == YES) {
        _textMark.hidden = NO;
        _textMarkLabel.hidden = NO;
        if (_imageMark.hidden == YES) {
            _textMark.frame = CGRectMake(_workSecondIcon.right - 45, _workCoverView.bottom - 30, 15, 15);
        } else {
            _textMark.frame = CGRectMake(_imageMark.left, _imageMark.top - 20, 15, 15);
        }
        _textMarkLabel.frame = CGRectMake(_textMark.right, _imageMark.top, 30, 20);
        _textMarkLabel.center = CGPointMake(_textMark.center.x + 20, _textMark.center.y);
        [self addAnimation:_textMark repeate:MAXFLOAT];
    } else {
        _textMark.hidden = YES;
        _textMarkLabel.hidden = YES;
        [_textMark.layer removeAllAnimations];
    }
}
- (void)addAnimation:(UIImageView *)mask repeate:(CGFloat)repeate
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    // 动画选项设定
    animation.duration = 0.5; // 动画持续时间
    animation.repeatCount = repeate; // 重复次数
    animation.autoreverses = YES; // 动画结束时执行逆动画
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    // 缩放倍数
    animation.fromValue = [NSNumber numberWithFloat:1.0]; // 开始时的倍率
    animation.toValue = [NSNumber numberWithFloat:1.25]; // 结束时的倍率
    // 添加动画
    [mask.layer addAnimation:animation forKey:@"scale-layer"];
}
- (void)touchUser:(UIButton *)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"plazzGoToUser" object:_model.uid];
}
- (void)changeAttention:(UIButton *)sender
{
    if ([[_model.user valueForKey:@"follow"] intValue]== 0) {
        if ([[NSUserDefaults standardUserDefaults] valueForKey:@"uid"] == nil) {
            //我的
            //提示请先登陆
            [JCAlertView showTwoButtonsWithTitle:@"未登录" Message:@"登录后才能继续操作" ButtonType:JCAlertViewButtonTypeCancel ButtonTitle:@"再看看" Click:^{

            } ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"去登录" Click:^{
                [[AppDelegate shareDelegate] chooseRootViewController];
            }];
        } else {
            [self requestAttention];
            
        }
    }
}
- (void)requestAttention
{
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url = [NSString stringWithFormat:@"http://123.57.1.143/api/user/%@/follow", [_model.user valueForKey:@"uid"]];

    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    NSString *header = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
    [session.requestSerializer setValue:header forHTTPHeaderField:@"authorization"];
    [session POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [netWorkManager stopMonitoring];
        //        NSLog(@"--------------数据请求成功---------------");
        [_attentionButton setImage:nil forState:UIControlStateNormal];
        [_attentionButton setTitle:@"已关注" forState: UIControlStateNormal];
        _attentionButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_attentionButton setTitleColor:[UIColor colorWithRed:0.600f green:0.600f blue:0.600f alpha:1.00f] forState:UIControlStateNormal];
        _attentionButton.layer.borderColor = [[UIColor clearColor] CGColor];
        _attentionButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeAttenArray" object:self];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          NSLog(@"error = %@", error);
    }];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (alertView.tag==12345){
        if (buttonIndex == 0) {
        }else if (buttonIndex == 1){
            //跳到登陆页
            [[AppDelegate shareDelegate] chooseRootViewController];
        }
    }
}


- (CGSize)boundingRectWithSize:(CGSize)size text:(NSString *)text font:(UIFont *)font
{
    NSDictionary *attribute = @{NSFontAttributeName: font};
    
    CGSize retSize = [text boundingRectWithSize:size
                                        options:\
                      NSStringDrawingTruncatesLastVisibleLine |
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                     attributes:attribute
                                        context:nil].size;
    
    return retSize;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
